﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Emoney.DataAccess;
using LiuYan.Base;


namespace LiuYan.Service
{
    public class BaseService
    {
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="tbName"></param>
        /// <returns></returns>
        public int Dels(string id, string tbName, bool b)
        {
            var ids = id.Split(',');
            var where = "";
            for (var i = 0; i < ids.Length; i++)
            {
                where += "or Id=" + ids[i];
            }
            string sql = b == true ?
                "delete " + tbName + " where " + where.Substring(2, where.Length - 2)
                : "update " + tbName + " set del='1' where " + where.Substring(2, where.Length - 2);
            return SqlHelper.ExecuteNonQuery(Connection.conStr, CommandType.Text, sql, null);
        }

        /// <summary>
        /// 获取一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="tbName"></param>
        /// <returns></returns>

        public DataTable GetOneData(int id, string tbName)
        {
            string sql = "select top(1) * from " + tbName + " where id=" + id;
            return SqlHelper.ExecuteDataset(Connection.conStr, CommandType.Text, sql, null).Tables[0];
        }
    }
}
